package logic

import (
	"context"
	"shenzhou-b/rpc/model/mysql"

	"shenzhou-b/rpc/car"
	"shenzhou-b/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *car.UserListRequest) (*car.UserListResponse, error) {
	// todo: add your logic here and delete this line

	u := mysql.User{}
	list, err := u.FindList(in.Status)
	if err != nil {
		return nil, err
	}

	var List []*car.UserItem
	for _, user := range list {
		List = append(List, &car.UserItem{
			Username: user.Username,
			Password: user.Password,
			Status:   user.Status,
		})
	}

	return &car.UserListResponse{UserItem: List}, nil
}
